package com.simpleclouddisk.controller;

import com.simpleclouddisk.common.Result;
import com.simpleclouddisk.domain.dto.ShareLinkUserInfo;
import com.simpleclouddisk.domain.entity.User;
import com.simpleclouddisk.service.ShareLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/shareLink")
public class ShareLinkController {

    @Autowired
    private ShareLinkService shareLinkService;

    @GetMapping("/count/{linkId}")
    public Result Count(@PathVariable Long linkId){
        long count = shareLinkService.count(linkId);
        return Result.ok(count);
    }

    @GetMapping("/{id}")
    public Result shareLink(@PathVariable Long id){
        Map<String,String> map = shareLinkService.shareLink(id);
        return Result.ok(map);
    }

    @GetMapping ("/parse/user/{url}")
    public Result parseUrl(@PathVariable("url") String url) {
        ShareLinkUserInfo user = shareLinkService.parseToShareLinkUserInfo(url);
        return Result.ok(user);
    }

    @GetMapping("/folder/{id}")
    public Result folder(@PathVariable Long id){
        List list = shareLinkService.folder(id);
        return Result.ok(list);
    }

    @GetMapping("/ownLink/{url}")
    public Result ownLink(@PathVariable String url){
        boolean bool = shareLinkService.parseShareLinkToUser(url);
        return Result.ok(bool);
    }
}
